package com.bicon.botu.mall.component.processor.rpc.fallback;

import com.bicon.botu.mall.component.processor.rpc.service.GoodsInvoker;
import com.bicon.botu.mall.goods.entity.Product;
import com.bicon.botu.mall.goods.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by L on 2017/2/13.
 */
@Service
public class GoodsInvokerImpl implements GoodsInvoker {


    @Autowired
    private IProductService productService;


    @Override
    public boolean updateProductState(String productIdsJson, String state) {
        List<Product> list = new ArrayList<>();
        String[] strings = productIdsJson.split(",");
        if (strings.length > 0) {
            for (String productId : strings) {
                Product product = new Product();
                product.setId(productId);
                product.setShowState(state);
                list.add(product);
            }
            return productService.updateBatchById(list);
        }
        return false;
    }
}
